package com.springboot.framework.controller;

import com.springboot.framework.annotation.ACS;
import com.springboot.framework.exception.BusinessException;
import com.springboot.framework.model.BuyerModel;
import com.springboot.framework.model.SellerModel;
import com.springboot.framework.service.BuyerService;
import com.springboot.framework.service.SellerService;
import com.springboot.framework.utils.ResponseVoUtil;
import com.springboot.framework.vo.ResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author SWF
 * @Date 2019/6/10 16:03
 **/
@Api(description = "【买家】用户")
@RestController
@RequestMapping("/buyer")
public class BuyerController extends BaseController {
    @Resource
    private BuyerService buyerService;

    @ACS(allowAnonymous = true)
    @ApiOperation(value = "买家登录",notes = "买家登录")
    @GetMapping("/login")
    public ResponseVO<BuyerModel> login(String openId, HttpServletRequest request){
        if(openId == null){
            return null;
        }
        BuyerModel buyerModel = buyerService.loginByOpenId(openId);
        if(buyerModel == null){
            throw new BusinessException("登录失败");
        }
        super.sessionUser(request,buyerModel);
        return ResponseVoUtil.success(buyerModel);
    }
}
